package com.lyf.demo;

import com.lyf.plugin.spi.SpiTestService;

import java.util.Optional;
import java.util.ServiceLoader;

/**
 * @AUTHOR LYF
 * @DATE 2022/6/11
 * @VERSION 1.0
 * @DESC
 */
public class TestSpi {
    public static void main(String[] args) {
        ServiceLoader<SpiTestService> loader = ServiceLoader.load(SpiTestService.class);
        Optional<SpiTestService> optionalSpiTestService = loader.findFirst();
        if(optionalSpiTestService.isEmpty()){
            System.out.println("cant..find..service..");
        }else{
            // 安装优先级进行排序
            loader.forEach(e->{
                e.testMethod();
            });
        }
    }
}
